<?php
namespace app\api\controller\V22;

use app\api\controller\Base;

class UserIntegralLog extends Base
{
    // 不需要验证
    protected $excludeValidateCheck = [
        'lists'
    ];

    // 定义自动实例化模型
    protected $ModelPath = 'UserIntegralLog';

    public function lists(){
        $params = request()->param();
        $currentPage = request()->param('page', 1);
        $start = ($currentPage - 1) * $this->pageSize;//1 0, 2 10, 3 20
        $type = request()->param('type', 'all');

        $userId = request()->UserModel->id;
        $map = [];

//        $model = $this->M->with(['ordersGoods']);
//        if($type != 'all')
//        {
//            $map[] = ['status', '=', $type];
//        }
        $list = $this->M
            ->where($map)
            ->where('user_id', $userId)
            ->append(['img', 'mode'])
            ->order('id DESC')
            ->limit($start, $this->pageSize)
            ->select();
//            ->paginate($this->pageSize)
//            ->toArray();
        $data = [];
//        $data['total_page'] = (int)ceil($list['total']/$this->pageSize);;
        $data['page_size'] = $this->pageSize;
        $data['page'] = $currentPage;//$list['current_page'];
        $data['lists'] = $list;// $list['data'];

        return showSuccess($data);
    }
}